import * as types from '../constants/OrderOpType'

const initialState = {
  dataList: [],
  orderId: ''
}

const deleteOrder = (state, index) => {
  let dl = []
  Object.assign(dl, state.dataList)
  dl.splice(index, 1)
  return {
    ...state,
    dataList: dl
  }
}

const order2Reducer = (state = initialState, action) => {
  switch (action.type) {
    case types.DELETE_ORDER:
      return deleteOrder(state, action.index)
      break
    case types.UPDATE_ORDER_LIST:
      return {
        ...state,
        dataList: action.list
      }
    default:
      return state
  }
}

export default order2Reducer
